package kg.aibek.preuler1;

public class Problem4 {

	private boolean isPalindrome(int number) {
		String str = number + "";

		char[] chs = str.toCharArray();
		for (int i = 0; i < str.length() / 2; i++) {
			if (chs[i] != chs[str.length() - 1 - i]) {
				return false;
			}
		}

		return true;
	}

	public void solve() {
		for (int i = 999 * 999; i > 0; i--) {
			if (isPalindrome(i) && isProduct(i)) {
				System.out.println(i);
				return;
			}
		}
		System.out.println("No found");
	}

	private boolean isProduct(int number) {
		for (int i = 999; i > 99; i--) {
			if (number % i == 0) {
				int n = (number / i);
				if (n > 99 && n < 1000) {
					return true;
				}
			}
		}
		return false;
	}

	public static void main(String[] args) {
		Problem4 p = new Problem4();
		p.solve();
	}
}
